Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on pro mini:
- 0 rxd rxd
- 1 txd txd
- 2 pd2
- 3 pd3
- 4 pd4
- 5 pd5
- 6 pd6
- 7 pd7
- 8 pb0 Data 0
- 9 pb1 Data 1
- 10 pb2
- 11 pb4
- 12 pb3
- 13 pb5
- A0 pc0 LCD D0
- A1 pc1 LCD D1
- A2 pc2 LCD D2
- A3 pc3 LCD D3
- A4 pc4 LCD RS
- A5 pc5 LCD /E
- A6 adc6
- A7 adc7
- LCD R/W goes to ground
- LCD Vlcd goes to 0-5V contrast pot.
- position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
- line 1 0 1 2 3 4 5 6 7 40 41 42 43 44 45 46 47
- */
- #include <avr/io.h>
- #include "usart.h"
- #include <avr/interrupt.h>
- #include "lcd.h"
- #define NOP() asm volatile ("nop"::)
- #define OUTPUT 1
- #define INPUT 0
- #define SetBit(BIT, PORT) PORT |= (1<<BIT)
- #define ClearBit(BIT, PORT) PORT &= ~(1<<BIT)
- #define IsHigh(BIT, PORT) (PORT & (1<<BIT)) != 0
- #define IsLow(BIT, PORT) (PORT & (1<<BIT)) == 0
- #define InBoundsI(v, l, h) ((v) >= (h)) ? (0) : ((v) <= (l)) ? (0) : (1)
- #define waitswipe() while((PINB & 0x03) == 0x03)
- unsigned long readCode(void);
- int main( void ) {
- unsigned int i;
- unsigned long capture;
- unsigned int facility;
- unsigned int serial;
- // set up directions
- DDRB = (INPUT << PB0 | INPUT << PB1 | INPUT << PB2 |INPUT << PB3 |INPUT << PB4 |INPUT << PB5 |INPUT << PB6 |INPUT << PB7);
- DDRD = (INPUT << PD0 | INPUT << PD1 | INPUT << PD2 |INPUT << PD3 |INPUT << PD4 |INPUT << PD5 |INPUT << PD6 |INPUT << PD7);
- DDRC = (OUTPUT << PC0 | OUTPUT << PC1 | OUTPUT << PC2 |OUTPUT << PC3 |OUTPUT << PC4 |OUTPUT << PC5 |INPUT << PD6 |INPUT << PD7);
- PORTB = 0x0C;
- lcd_init();
- lcd_goto(0);
- lcd_putstr("Ready");
- for ( i = 0; i < 65534; i++) NOP(); // startup delay for screen
- lcd_cls();
- lcd_putstr("Ready");
- while(1) {
- waitswipe();
- capture = readCode();
- facility = (capture >> 16) & 255;
- serial = capture & 0xFFFF;
- lcd_goto(0);
- lcd_putstr("F:");
- print3(facility);
- lcd_goto(40);
- lcd_putstr("SN:");
- print5(serial);
- }
- }
- //------------------------| FUNCTIONS |------------------------
- unsigned long readCode(void) {
- unsigned long data;
- unsigned long timeout;
- data = 0;
- while(1) {
- for(timeout = 2000*8; ((timeout != 0) && (( PINB & 0x03) == 0x03)); timeout--);
- if (timeout != 0) {
- if (PINB & 0x01) {
- data |= 0x01;
- }
- data <<= 1;
- while((PINB & 0x03) != 0x03);
- } else {
- return data >> 2 ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement